#!/usr/bin/env python

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'delete_admin_form.ui'
#
# Created: Thu Apr 30 02:33:37 2009
#      by: The PyQt User Interface Compiler (pyuic) 3.17.6
#
# WARNING! All changes made in this file will be lost!


from qt import *
import anydbm

class delete_admin_form(QDialog):
    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        """
        __init__(self,parent = None,name = None,modal = 0,fl = 0):
            deleting a new Administrator when logging in as Manager
            deleting a new Administrator requires connection to the Database which is "Admin_Accounts" file
        """
        QDialog.__init__(self,parent,name,modal,fl)

        if not name:
            self.setName("delete_admin_form")



        self.groupBox6 = QGroupBox(self,"groupBox6")
        self.groupBox6.setGeometry(QRect(10,10,390,70))

        self.lineEdit6 = QLineEdit(self.groupBox6,"lineEdit6")
        self.lineEdit6.setGeometry(QRect(130,30,240,22))

        self.textLabel3 = QLabel(self.groupBox6,"textLabel3")
        self.textLabel3.setGeometry(QRect(20,30,99,20))

        self.delete_admin_button = QPushButton(self,"delete_admin_button")
        self.delete_admin_button.setGeometry(QRect(300,90,103,27))

        self.cancel_delete_btn = QPushButton(self,"cancel_delete_btn")
        self.cancel_delete_btn.setGeometry(QRect(190,90,103,27))

        self.languageChange()

        self.resize(QSize(411,128).expandedTo(self.minimumSizeHint()))
        self.clearWState(Qt.WState_Polished)

        self.connect(self.delete_admin_button,SIGNAL("clicked()"),self.delete_admin_button_clicked)
        self.connect(self.cancel_delete_btn,SIGNAL("clicked()"),self.cancel_delete_btn_clicked)


    def languageChange(self):
        self.setCaption(self.__tr("Delete Admin"))
        self.groupBox6.setTitle(self.__tr("Admistrator"))
        self.textLabel3.setText(self.__tr("Adminstrator"))
        self.delete_admin_button.setText(self.__tr("&Delete"))
        self.delete_admin_button.setAccel(QKeySequence(self.__tr("Alt+D")))
        self.cancel_delete_btn.setText(self.__tr("&Cancel"))
        self.cancel_delete_btn.setAccel(QKeySequence(self.__tr("Alt+C")))


    def delete_admin_button_clicked(self):
        """
        def delete_admin_button_clicked(self):
            when clicking the "delete admin" button
            if the name is found it'll be deleted, if not an error message will appear
        """
        admin_db = anydbm.open('Admin_Accounts','rw')
        deleted_admin = str(self.lineEdit6.text())
        if deleted_admin == '':
            Message = 'You must enter a valid admin to delete!'
            QMessageBox.critical(self,"Warning!",Message,QMessageBox.Ok)
        elif  not admin_db.has_key(deleted_admin):
            Message = 'adminstrator you searched not exist !'
            QMessageBox.critical(self,"Warning!",Message,QMessageBox.Ok)
        else:
            del admin_db[deleted_admin]
            Message = '%s is deleted successfully' %deleted_admin
            QMessageBox.information(self,"Info!",Message,QMessageBox.Ok)
            self.hide()


    def cancel_delete_btn_clicked(self):
        self.hide()

    def __tr(self,s,c = None):
        return qApp.translate("delete_admin_form",s,c)
